/**
* Oxide
*
* Copyright (c) 2011 Dinosaur Kick Pty Ltd, All rights reserved.
*
* This source code is made available under the "Modified BSD" licensing arrangement.
* See license.txt for details.
*/
// ----------------------------------------------------------------------------
#include "token_identity.hpp"
// ----------------------------------------------------------------------------
#ifndef O2_TOKEN_INC
#define O2_TOKEN_INC
namespace o2 {
// ----------------------------------------------------------------------------

template <typename StringT>
struct basic_token
{
	typedef StringT string_type;
	typedef typename std::char_traits<typename string_type::value_type>::off_type offset_type;

	basic_token(void)
		: offset(0)
		, line(0)
		, column(0)
		, identity(TOK_UNKNOWN)
		{ }

	bool operator== (const basic_token& tok) const
	{
		return offset == tok.offset
			&& line == tok.line
			&& column == tok.column
			&& identity == tok.identity
			&& content == tok.content;
	}
	
	bool operator!= (const basic_token& tok) const
	{
		return !(*this == tok);
	}
	
	offset_type offset;
	offset_type line;
	offset_type column;
	token_identity identity;
	string_type content;
};

// ----------------------------------------------------------------------------

typedef basic_token<std::string> token;
typedef basic_token<std::wstring> wtoken;

// ----------------------------------------------------------------------------

template <typename CharT, typename TraitsT, typename StringT>
std::basic_ostream<CharT, TraitsT>& operator<< (std::basic_ostream<CharT, TraitsT>& stream, const basic_token<StringT>& tok)
{
	stream << tok.identity;
	stream << '[';
	stream << tok.line;
	stream << ']';

	if (!tok.content.empty())
	{
		stream << ' ';
		stream << '(';
		stream << tok.content;
		stream << ')';
	}
	
	return stream;
}

// ----------------------------------------------------------------------------
} // namespace o2
#endif // O2_TOKEN_INC
// ----------------------------------------------------------------------------
